#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by Zoo on 2018/1/17

from PIL import Image
import sys,os

def cover(path, width, height):
	readPath = path
	file = os.path.split(path)[-1].split('.')
	name, suffix = file[0], file[-1]
	print 'reading', name
	if suffix.lower() in ['png', 'jpg', 'bmp']:
		img = Image.open(readPath)
		print 'resizing',readPath
		out = img.resize((width,height),Image.ANTIALIAS)
		localPath = path[:0]+name+"_new."+suffix
		print 'writting', localPath
		out.save(localPath, "PNG")
		pass
	pass

if __name__ == '__main__':
	if len(sys.argv) == 4:
		cover(sys.argv[1], int(sys.argv[2]), int(sys.argv[3]))
	else:
		print 'usage: resize "file path" width height'
	pass